<template>
  <div>
    <van-nav-bar :title="title" />
    <van-form @submit="$emit('onSubmit', { username, password })">
      <van-field
        v-model="username"
        label="用户名"
        type="text"
        name="username"
        required
        placeholder="请输入用户名"
        :rules="[
          { required: true, message: '用户名不能为空' },
          { pattern: /^\w{5,}$/, message: '用户名至少5位' },
        ]"
      />
      <van-field
        v-model="password"
        required
        placeholder="请输入密码"
        label="密码"
        type="password"
        name="password"
        :rules="[
          { required: true, message: '密码不能为空' },
          { pattern: /^\w{6,}$/, message: '密码至少包含6个字符' },
        ]"
      />
      <div style="margin: 16px">
        <!--  不能写死 -->

        <slot name="btn"></slot>
      </div>
    </van-form>

    <!-- 不能写死 -->
    <slot name="footer"></slot>
  </div>
</template>

<script>
/*
  学习目标：封装Form组件
  步骤：
     1. 新建HmForm组件
     2. 
     3. 
*/
export default {
  props: { title: String },
  data() {
    return {
      username: "zhangsan",
      password: "123456",
    };
  },
};
</script>

<style lang="less" scoped>
.link {
  color: #069;
  font-size: 12px;
  padding-right: 20px;
  float: right;
}
</style>